/**
 * #item
 *
 * @type        aty-tabspace
 * @cn          页签占位
 * @menu        导航
 * @stPlugin    false
 * @stContainer true
 */
// 扩展属性
/**
 * #extendproperty
 *
 * @name    slot
 * @cn      定制页签内容
 * @type    list
 * @options [label]
 * @description  aty-tabspace插槽，<aty-tabspace slot="label">自定义内容</aty-tabspace>
 */
import config from '../../../../config/config.js'
// 模块
const module = {
  name: config.prefix + '-tabs-tabspace',
  components: {},
  props: {
    /**
     * #property
     *
     * @name    name
     * @cn      页签标识
     * @type    string
     * @description 页签的唯一标识
     */
    name: {
      type: String
    },
    /**
     * #property
     *
     * @name    label
     * @cn      文字
     * @type    string,function
     * @description 页签上的文字
     */
    label: {
      type: [String, Function],
      default: ''
    },
    /**
     * #property
     *
     * @name    icon
     * @cn      图标
     * @type    icon
     * @description 页签文字前边的图标
     */
    icon: {
      type: String
    },
    /**
     * #property
     *
     * @name    splitPosition
     * @cn      分屏位置
     * @type    list
     * @value   left
     * @options [left, right]
     * @description 分屏模式下，处于左屏还是右屏
     */
    splitPosition: {
      type: String,
      default: 'left'
    },
    /**
     * #property
     *
     * @name    splitable
     * @cn      可分屏
     * @type    boolean
     * @bind    must
     * @value   true
     * @description 是否可分屏
     */
    splitable: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {
      currentName: this.name,
      scope: {
        className: config.prefix + '-tabs-tabspace'
      },
      show: false,
      disabled: true,
      closable: false,
      isSpace: true,
      isLast: false
    }
  },
  methods: {
    updateNav () {
      if (typeof this.$parent.updateNav === 'function') {
        this.$parent.updateNav()
      } else {
        let parent = this.$parent.$parent
        while (typeof parent.updateNav !== 'function') {
          parent = parent.$parent
        }
        parent.updateNav()
      }
    }
  },
  watch: {
    name (val) {
      this.currentName = val
      this.updateNav()
    },
    label () {
      this.updateNav()
    },
    icon () {
      this.updateNav()
    },
    disabled () {
      this.updateNav()
    }
  },
  mounted () {
    this.updateNav()
  },
  destroyed () {
    this.updateNav()
  }
}
export default module
